package liu.de.config;

import com.fasterxml.classmate.TypeResolver;
import liu.de.dto.TextBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import springfox.documentation.schema.AlternateTypeRule;
import springfox.documentation.schema.AlternateTypeRuleConvention;
import springfox.documentation.schema.AlternateTypeRules;

import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

/**
 * @author liude
 */
@Configuration
public class SwaggerConfig {
    @Bean
    public AlternateTypeRuleConvention pageableConvention(final TypeResolver resolver) {
        return new AlternateTypeRuleConvention() {
            @Override
            public int getOrder() {
                return Ordered.HIGHEST_PRECEDENCE;
            }

            @Override
            public List<AlternateTypeRule> rules() {
                return newArrayList(AlternateTypeRules.newRule(resolver.resolve(Bean.class), resolver.resolve(TextBean.class)));
            }
        };
    }
}
